package com.usbserial.driver;

import android.hardware.usb.UsbDeviceConnection;

import com.usbserial.exception.UsbSerialException;

/**
 * Driver interface that abstracts a specific USB-to-serial chipset implementation.
 */
public interface UsbSerialDriver {

    void open(UsbDeviceConnection connection) throws UsbSerialException;

    void close() throws UsbSerialException;

    void setBaudRate(int baudRate) throws UsbSerialException;

    void setDataBits(int dataBits) throws UsbSerialException;

    void setStopBits(int stopBits) throws UsbSerialException;

    void setParity(int parity) throws UsbSerialException;

    void setFlowControl(int mode) throws UsbSerialException;

    void setDTR(boolean value) throws UsbSerialException;

    void setRTS(boolean value) throws UsbSerialException;

    void registerReadCallback(ReadListener listener) throws UsbSerialException;

    void unregisterReadCallback() throws UsbSerialException;

    int write(byte[] src, int timeout) throws UsbSerialException;

    interface ReadListener {
        void onReceived(byte[] data);

        void onError(Exception error);
    }
}
